<template>
  <div class="educationadd">
    <div class="educationaddchild">
      <div class="educationaddchildcont">
        <p class="educationaddlift">{{schoolname}}</p>
      </div>
      <van-divider color="#E8E8E8" />

      <div v-if="!xlshow&&!zelbshow">
        <van-form @submit="onSubmit">
          <van-field v-model="schoolnamemode" name="schoolname" :placeholder="schoolnamepl" :rules="[{ required: true, message: messagename},{
              validator
            }]" />
          <van-divider color="#E8E8E8" />
          <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">保存</van-button>
          </div>
        </van-form>
      </div>
      <div v-if="xlshow">
        <van-form @submit="onSubmit">
          <van-field readonly clickable name="qzzt" :value="schoolnamemode" :placeholder="schoolnamepl"
            @click="showPickerqwdd = true" :rules="[{ required: true, message: ' ' }]" />
          <van-popup v-model="showPickerqwdd" position="bottom">
            <van-picker show-toolbar value-key="name" :columns="columnsqwdd" :item-height="45" @confirm="onConfirmgqwdd"
              @cancel="showPickerqwdd = false" />
          </van-popup>
          <van-divider color="#E8E8E8" />
          <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">保存</van-button>
          </div>
        </van-form>
      </div>

      <div v-if="zelbshow">
        <van-form @submit="onSubmit">
          <van-field readonly clickable name="qzzt" :value="schoolnamemode" :placeholder="schoolnamepl"
            @click="showPickerzwlb = true" :rules="[{ required: true, message: ' ' },
            ]" />
          <van-popup v-model="showPickerzwlb" position="bottom">
            <van-picker show-toolbar value-key="name" :columns="zwlb" @confirm="onConfirmgzwlb"
              @cancel="showPickerzwlb = false" />
          </van-popup>
          <van-divider color="#E8E8E8" />
          <div style="margin: 16px;">
            <van-button round block type="info" native-type="submit">保存</van-button>
          </div>
        </van-form>
      </div>
    </div>
  </div>
</template>
<script>
import DICTIONARY from '@/api/Dictionary'

export default {
  data () {
    return {
      showPickerqwdd: false,
      showPickerzwlb: false,
      xlshow: false,
      zelbshow: false,
      columnsqwdd: [],
      zwlb: [],
      messagename: ' ',
      schoolname: '', // 大类名称
      schoolnamepl: '',
      schoolnamemode: '', // 输入的名称
      namecode: '',
      scoolid: ''
    }
  },
  computed: {},
  methods: {
    // 向父级传递参数
    onSubmit () {
      console.log(1)
      let that = this
      // 调用父级函数
      that.$emit(
        'industryca',
        this.namecode,
        this.schoolnamemode,
        this.scoolid
      )
    },
    // 选择期望地点赋值
    onConfirmgqwdd (value) {
      this.schoolnamemode = value.name
      this.scoolid = value.val
      this.showPickerqwdd = false
    },
    // 弹出选择职位列表
    onConfirmgzwlb (value) {
      this.schoolnamemode = value.name
      this.scoolid = value.val
      this.showPickerzwlb = false
    },
    // 判断是否全是空格
    validator () {
      console.log(this.schoolnamemode.trim().length, 's')
      if (this.schoolnamemode.trim().length === 0) {
        this.schoolnamemode = ''
      }
    },
    // 获取父级页面传递过来的参数
    substate (namecode, name) {
      if (namecode === 'education') {
        this.xlshow = true
      } else {
        this.xlshow = false
      }
      if (namecode === 'jobCategory') {
        this.zelbshow = true
      } else {
        this.zelbshow = false
      }
      this.namecode = namecode
      this.schoolname = name
      this.schoolnamemode = ''
      this.schoolnamepl = '请输入' + name
      this.$forceUpdate()
    },
    // 获取字段表
    adminDict () {
      let that = this
      let params = 'area,current_status,work_mode,education'
      DICTIONARY.adminDict(params).then(res => {
        if (res.data.code === 200) {
          that.columnsqwdd = res.data.data.education
          that.zwlb = res.data.data.work_mode

          // that.category = res.data.data.work_mode;
          // that.us_company_nature = res.data.data.company_nature;
          // that.us_company_scale = res.data.data.scale;
        }
      })
    }
  },
  created () {
    this.adminDict()
  }
}
</script>
<style scoped></style>
